package com.glsc.ngateway.opmanage.service;

import com.alibaba.fastjson.JSON;
import com.glsc.ngateway.common.api.common.utils.DateUtil;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.ledger.BusinessLedger;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.ledger.BusinessLedgerTask;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.settlement.SettlementLog;
import com.glsc.ngateway.opmanage.dto.*;
import com.glsc.ngateway.opmanage.service.ledger.LedgerService;
import com.glsc.ngateway.opmanage.service.settlement.SettlementLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DesktopService {

    @Resource
    private LedgerService ledgerService;

    @Resource
    private DictionaryService dictionaryService;

    @Resource
    private MailService mailService;

    @Resource
    private SettlementLogService settlementLogService;


    /**
     * 股衍运营岗-今日桌面
     *
     * @param request
     * @return
     */
    public PlatformResponse<LedgerDesktopDto> screenYsp(String date, HttpServletRequest request) {
        LedgerDesktopDto res = new LedgerDesktopDto();
        List<LedgerDesktopDtoItem> incomeList = Lists.newArrayList();
        List<LedgerDesktopDtoItem> customerList = Lists.newArrayList();
        List<LedgerDesktopDtoItem> swapList = Lists.newArrayList();
        List<LedgerDesktopDtoItem> foundationList = Lists.newArrayList();

        res.setCustomerList(customerList);
        res.setIncomeList(incomeList);
        res.setFoundationList(foundationList);
        res.setSwapList(swapList);
        res.setSettlementList(Lists.newArrayList());

        Map<String, LedgerPerfDtoItem> perfMap = new HashedMap();
        perfMap.put("孙伟平", LedgerPerfDtoItem.builder().userName("孙伟平").postName("股衍运营岗").userOaAccount("sunwp").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
        perfMap.put("陶轶铭", LedgerPerfDtoItem.builder().userName("陶轶铭").postName("股衍运营岗").userOaAccount("taoym").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
        perfMap.put("赵正彦", LedgerPerfDtoItem.builder().userName("赵正彦").postName("股衍运营岗").userOaAccount("zzy").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
        perfMap.put("毕翠翠", LedgerPerfDtoItem.builder().userName("毕翠翠").postName("股衍运营岗").userOaAccount("bicc").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());


        Map<String, Object> param = new HashMap<>();
        List<String> typeList = Arrays.asList("jrsc_gyyygtz");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        param.put("GTE_createTime", DateUtil.getNowDateString());
        param.put("LTE_createTime", dateFormat.format(calendar.getTime()));

        ArrayList<LedgerDesktopDtoItem> arrayList = Lists.newArrayList();
        res.setTaskList(arrayList);

        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (Objects.nonNull(page) && CollectionUtils.isNotEmpty(page.getContent())) {
            BusinessLedger ledger = page.getContent().get(0);
            if (Objects.nonNull(ledger)) {
                List<BusinessLedgerTask> businessLedgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                if (CollectionUtils.isNotEmpty(businessLedgerTasks)) {
                    for (BusinessLedgerTask task : businessLedgerTasks) {
                        arrayList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                    }
                }
            }
        }

        List<LedgerPerfDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerPerfDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);

        /*//查询未完成的台账
        Map<String, Object> param = new HashMap<>();
        param.put("EQ_status", "0");
        List<String> typeList = Arrays.asList("kyc_org", "jijin_shenshu", "shouyi_pingzheng", "jiaoyi_yewu");
        param.put("INSTR_toTaskType", String.join(",", typeList));

        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (CollectionUtils.isNotEmpty(page.getContent())) {
            LocalDateTime oneWeekAgo = LocalDateTime.now().minus(1, ChronoUnit.WEEKS);
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            for (BusinessLedger ledger : page.getContent()) {
                List<BusinessLedgerTask> taskList = ledgerService.listLedgerByLedgerId(ledger.getId());
                taskList = taskList.stream().filter(e -> ("Y".equals(e.getWorkValueRequire()) && "0".equals(e.getStatus()))).collect(Collectors.toList());
                taskList = taskList.stream().sorted(Comparator.comparing(BusinessLedgerTask::getTaskSort)).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(taskList)) {
                    continue;
                }
                BusinessLedgerTask task = taskList.get(0);

                if ("kyc_org".equals(ledger.getToTaskType())) {
                    customerList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("jijin_shenshu".equals(ledger.getToTaskType())) {
                    foundationList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());

                } else if ("shouyi_pingzheng".equals(ledger.getToTaskType())) {
                    //只查询一周以内未完成的交易凭证
                    //if (ledger.getCreateTime().isAfter(oneWeekAgo)) {
                    incomeList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                    LedgerPerfDtoItem perfDtoItem = null;
                    perfDtoItem = perfMap.get(ledger.getCreateName());
                    if (Objects.nonNull(perfDtoItem)) {
                        if (ledger.getCreateTime().format(formatter).equals(date)) {
                            perfDtoItem.setIncomeHour(perfDtoItem.getIncomeHour() + 20);
                            perfDtoItem.setManHour(perfDtoItem.getManHour() + 20);
                        }
                    }
                    //}
                } else if ("jiaoyi_yewu".equals(ledger.getToTaskType())) {
                    swapList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                }
            }

            incomeList = incomeList.stream().sorted(Comparator.comparing(LedgerDesktopDtoItem::getLedgerId)).collect(Collectors.toList());
            if (incomeList.size() > 5) {
                incomeList = incomeList.subList(Math.max(incomeList.size() - 5, 0), incomeList.size());
                incomeList = incomeList.stream().sorted(Comparator.comparing(LedgerDesktopDtoItem::getLedgerId).reversed()).collect(Collectors.toList());
                res.setIncomeList(incomeList);
            }
        }


        //查询当日完成的台账
        Map<String, Object> finishParam = new HashMap<>();
        finishParam.put("EQ_status", "1");
        finishParam.put("EQ_finishTime", date);
        finishParam.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> finishPage = ledgerService.findLedgerPage(1, 1000, finishParam);
        if (CollectionUtils.isNotEmpty(finishPage.getContent())) {
            Set<String> nameSet = perfMap.keySet();
            for (BusinessLedger ledger : finishPage.getContent()) {
                LedgerPerfDtoItem perfDtoItem = null;
                if (nameSet.contains(ledger.getFinishUserName())) {
                    perfDtoItem = perfMap.get(ledger.getFinishUserName());
                }

                if ("kyc_org".equals(ledger.getToTaskType())) {
                    customerList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());

                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    Set<String> finishNameSet = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).map(BusinessLedgerTask::getFinishUserName).collect(Collectors.toSet());
                    if (CollectionUtils.isEmpty(finishNameSet)) {
                        continue;
                    }
                    if (finishNameSet.size() == 1) {
                        if (Objects.nonNull(perfDtoItem)) {
                            perfDtoItem.setCustomerHour(perfDtoItem.getCustomerHour() + 30);
                            perfDtoItem.setManHour(perfDtoItem.getManHour() + 30);
                        }
                    } else if (finishNameSet.size() > 1) {
                        List<String> nameList = finishNameSet.stream().collect(Collectors.toList());
                        LedgerPerfDtoItem name1 = perfMap.get(nameList.get(0));
                        name1.setCustomerHour(name1.getCustomerHour() + 15);
                        name1.setManHour(name1.getManHour() + 15);

                        LedgerPerfDtoItem name2 = perfMap.get(nameList.get(1));
                        name2.setCustomerHour(name2.getCustomerHour() + 15);
                        name2.setManHour(name2.getManHour() + 15);
                    }
                } else if ("jijin_shenshu".equals(ledger.getToTaskType())) {
                    foundationList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    if (Objects.nonNull(perfDtoItem)) {
                        perfDtoItem.setFoundationHour(perfDtoItem.getFoundationHour() + 20);
                        perfDtoItem.setManHour(perfDtoItem.getManHour() + 20);
                    }
                } else if ("shouyi_pingzheng".equals(ledger.getToTaskType())) {
                    incomeList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    if (Objects.nonNull(perfDtoItem)) {
                        perfDtoItem.setIncomeHour(perfDtoItem.getIncomeHour() + 10);
                        perfDtoItem.setManHour(perfDtoItem.getManHour() + 10);
                    }
                } else if ("jiaoyi_yewu".equals(ledger.getToTaskType())) {
                    swapList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    ledgerTasks = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerPerfDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }

                        if (StringUtils.isNotBlank(task.getWorkValue())) {
                            try {
                                Integer count = Integer.parseInt(task.getWorkValue().trim());

                                if (Objects.nonNull(count) && count > 0) {
                                    if (task.getWorkType().contains("交易簿记数量")) {
                                        taskLedgerPerfDtoItem.setSwapHour(taskLedgerPerfDtoItem.getSwapHour() + 10 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 10 * count);
                                    } else if (task.getWorkType().contains("交易报送数量")) {
                                        taskLedgerPerfDtoItem.setSwapHour(taskLedgerPerfDtoItem.getSwapHour() + 3 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 3 * count);
                                    } else if (task.getWorkType().contains("交易确认书附件")) {
                                        taskLedgerPerfDtoItem.setSwapHour(taskLedgerPerfDtoItem.getSwapHour() + 2 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 2 * count);
                                    }
                                }
                            } catch (Exception e) {
                                log.error("今日桌面互换期权计算异常{}", JSON.toJSONString(task));
                            }
                        }
                    }
                }
            }
        }

        //查询清算日志
        List<SettlementLog> settlementLogs = settlementLogService.listNew5DataList();
        if (CollectionUtils.isNotEmpty(settlementLogs)) {
            Set<String> nameSet = perfMap.keySet();
            for (SettlementLog settlementLog : settlementLogs) {
                if (settlementLog.getSettlementDate().equals(date)) {
                    if (nameSet.contains(settlementLog.getCreateName())) {
                        LedgerPerfDtoItem perfDtoItem = perfMap.get(settlementLog.getCreateName());
                        perfDtoItem.setSettlementHour(perfDtoItem.getSettlementHour() + 90);
                        perfDtoItem.setManHour(perfDtoItem.getManHour() + 90);
                    }
                }
            }
            res.setSettlementList(settlementLogs);
        }

        List<LedgerPerfDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerPerfDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);*/

        return PlatformResponse.successData(res);
    }


    /**
     * 今日桌面-综合运营
     *
     * @param request
     * @return
     */
    public PlatformResponse<LedgerZongHeDto> screenZongHe(String date, HttpServletRequest request) {
        LedgerZongHeDto res = new LedgerZongHeDto();
        //党务事项dangwu
        List<LedgerDesktopDtoItem> dangWuList = Lists.newArrayList();
        //综合运营事项zonghe_shiwu
        List<LedgerDesktopDtoItem> zongHeList = Lists.newArrayList();
        //人力事项管理renli_shixiang
        List<LedgerDesktopDtoItem> renLiList = Lists.newArrayList();
        //系统权限管理xitong_quanxian_gl
        List<LedgerDesktopDtoItem> xiTongList = Lists.newArrayList();
        //自有资金账户管理zhanghu_guanli
        List<LedgerDesktopDtoItem> ziYouZiJinList = Lists.newArrayList();
        //交易单元管理jiaoyi_danyuan_gl
        List<LedgerDesktopDtoItem> jiaoYiDanYuanList = Lists.newArrayList();
        //其他工作jrscqt
        List<LedgerDesktopDtoItem> qiTaList = Lists.newArrayList();

        res.setDangWuList(dangWuList);
        res.setZongHeList(zongHeList);
        res.setRenLiList(renLiList);
        res.setXiTongList(xiTongList);
        res.setZiYouZiJinList(ziYouZiJinList);
        res.setJiaoYiDanYuanList(jiaoYiDanYuanList);
        res.setQiTaList(qiTaList);

        Map<String, LedgerZongHeDtoItem> perfMap = new HashedMap();
        perfMap.put("肖丹", LedgerZongHeDtoItem.builder().userName("肖丹").postName("综合运营岗").userOaAccount("xiaod").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());
        perfMap.put("周洁", LedgerZongHeDtoItem.builder().userName("周洁").postName("综合运营岗").userOaAccount("zhoujie").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());


        Map<String, Object> param = new HashMap<>();
        List<String> typeList = Arrays.asList("jrsc_zhyygtz");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        param.put("GTE_createTime", DateUtil.getNowDateString());
        param.put("LTE_createTime", dateFormat.format(calendar.getTime()));

        ArrayList<LedgerDesktopDtoItem> arrayList = Lists.newArrayList();
        res.setTaskList(arrayList);

        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (Objects.nonNull(page) && CollectionUtils.isNotEmpty(page.getContent())) {
            BusinessLedger ledger = page.getContent().get(0);
            if (Objects.nonNull(ledger)) {
                List<BusinessLedgerTask> businessLedgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                if (CollectionUtils.isNotEmpty(businessLedgerTasks)) {
                    for (BusinessLedgerTask task : businessLedgerTasks) {
                        arrayList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                    }
                }
            }
        }

        List<LedgerZongHeDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerZongHeDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);


       /* //查询未完成的台账
        Map<String, Object> param = new HashMap<>();
        param.put("EQ_status", "0");
        List<String> typeList = Arrays.asList("dangwu", "zonghe_shiwu", "renli_shixiang", "xitong_quanxian_gl", "zhanghu_guanli", "jiaoyi_danyuan_gl", "jrscqt");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (CollectionUtils.isNotEmpty(page.getContent())) {
//            LocalDateTime oneWeekAgo = LocalDateTime.now().minus(1, ChronoUnit.WEEKS);
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            for (BusinessLedger ledger : page.getContent()) {
                List<BusinessLedgerTask> taskList = ledgerService.listLedgerByLedgerId(ledger.getId());
                taskList = taskList.stream().filter(e -> ("Y".equals(e.getWorkValueRequire()) && "0".equals(e.getStatus()))).collect(Collectors.toList());
                taskList = taskList.stream().sorted(Comparator.comparing(BusinessLedgerTask::getTaskSort)).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(taskList)) {
                    continue;
                }
                BusinessLedgerTask task = taskList.get(0);
                if ("dangwu".equals(ledger.getToTaskType())) {
                    //党务事项
                    dangWuList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("zonghe_shiwu".equals(ledger.getToTaskType())) {
                    //综合运营事项
                    zongHeList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("renli_shixiang".equals(ledger.getToTaskType())) {
                    //人力事项管理
                    renLiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("xitong_quanxian_gl".equals(ledger.getToTaskType())) {
                    //系统权限管理
                    xiTongList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("zhanghu_guanli".equals(ledger.getToTaskType())) {
                    //自有资金账户管理
                    ziYouZiJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("jiaoyi_danyuan_gl".equals(ledger.getToTaskType())) {
                    //交易单元管理
                    jiaoYiDanYuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("jrscqt".equals(ledger.getToTaskType())) {
                    //其他工作
                    qiTaList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                }
            }
        }


        //查询当日完成的台账
        Map<String, Object> finishParam = new HashMap<>();
        finishParam.put("EQ_status", "1");
        finishParam.put("EQ_finishTime", date);
        finishParam.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> finishPage = ledgerService.findLedgerPage(1, 1000, finishParam);
        if (CollectionUtils.isNotEmpty(finishPage.getContent())) {
            Set<String> nameSet = perfMap.keySet();
            for (BusinessLedger ledger : finishPage.getContent()) {
                LedgerZongHeDtoItem perfDtoItem = null;
                if (nameSet.contains(ledger.getFinishUserName())) {
                    perfDtoItem = perfMap.get(ledger.getFinishUserName());
                }
                if (Objects.isNull(perfDtoItem)) {
                    continue;
                }

                if ("dangwu".equals(ledger.getToTaskType())) {
                    //党务事项
                    dangWuList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setDangWuHour(perfDtoItem.getDangWuHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                } else if ("zonghe_shiwu".equals(ledger.getToTaskType())) {
                    //综合运营事项
                    zongHeList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setZongHeHour(perfDtoItem.getZongHeHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);

                } else if ("renli_shixiang".equals(ledger.getToTaskType())) {
                    //人力事项管理
                    renLiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setRenLiHour(perfDtoItem.getRenLiHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);

                } else if ("xitong_quanxian_gl".equals(ledger.getToTaskType())) {
                    //系统权限管理
                    xiTongList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    List<BusinessLedgerTask> finishTaskList = ledgerTasks.stream().filter(e -> "1".equals(e.getStatus())).collect(Collectors.toList());
                    if (CollectionUtils.isEmpty(finishTaskList)) {
                        continue;
                    }
                    for (BusinessLedgerTask ledgerTask : finishTaskList) {
                        LedgerZongHeDtoItem thisPerfDtoItem = perfMap.get(ledger.getFinishUserName());
                        if (Objects.isNull(thisPerfDtoItem)) {
                            continue;
                        }
                        try {
                            Integer count = Integer.parseInt(ledgerTask.getWorkValue().trim());
                            thisPerfDtoItem.setXiTongHour(thisPerfDtoItem.getXiTongHour() + count * 20);
                            thisPerfDtoItem.setManHour(thisPerfDtoItem.getManHour() + count * 20);

                        } catch (Exception e) {
                            log.error("今日桌面系统权限计算异常{}", JSON.toJSONString(ledgerTask));
                        }
                    }

                } else if ("zhanghu_guanli".equals(ledger.getToTaskType())) {
                    //自有资金账户管理
                    ziYouZiJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setZiYouZiJinHour(perfDtoItem.getZiYouZiJinHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                } else if ("jiaoyi_danyuan_gl".equals(ledger.getToTaskType())) {
                    //交易单元管理
                    jiaoYiDanYuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setJiaoYiDanYuanHour(perfDtoItem.getJiaoYiDanYuanHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                } else if ("jrscqt".equals(ledger.getToTaskType())) {
                    //其他工作
                    qiTaList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setQiTaHour(perfDtoItem.getQiTaHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                }
            }
        }

        List<LedgerZongHeDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerZongHeDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);*/

        return PlatformResponse.successData(res);
    }


    /**
     * 今日桌面-交易岗
     *
     * @param request
     * @return
     */
    public PlatformResponse<LedgerJiaoYiDto> screenJiaoYi(String date, HttpServletRequest request) {
        LedgerJiaoYiDto res = new LedgerJiaoYiDto();
        //大宗交易dazong_jiaoyi
        List<LedgerDesktopDtoItem> daZongList = Lists.newArrayList();
        //自有股质/行权融资guzhi_xingquan
        List<LedgerDesktopDtoItem> ziYouGuZhiList = Lists.newArrayList();
        //基金投顾jijin_tougu
        List<LedgerDesktopDtoItem> jiJinList = Lists.newArrayList();


        res.setDaZongList(daZongList);
        res.setZiYouGuZhiList(ziYouGuZhiList);
        res.setJiJinList(jiJinList);


        Map<String, LedgerJiaoYiDtoItem> perfMap = new HashedMap();
        perfMap.put("范漪漪", LedgerJiaoYiDtoItem.builder().userName("范漪漪").userOaAccount("fanyy").postName("交易岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
        perfMap.put("安恬", LedgerJiaoYiDtoItem.builder().userName("安恬").userOaAccount("ant").postName("交易岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
        perfMap.put("陈诗佳", LedgerJiaoYiDtoItem.builder().userName("陈诗佳").userOaAccount("chenshj").postName("交易岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());

        Map<String, Object> param = new HashMap<>();
        List<String> typeList = Arrays.asList("jrsc_zhyygtz");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        param.put("GTE_createTime", DateUtil.getNowDateString());
        param.put("LTE_createTime", dateFormat.format(calendar.getTime()));

        ArrayList<LedgerDesktopDtoItem> arrayList = Lists.newArrayList();
        res.setTaskList(arrayList);

        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (Objects.nonNull(page) && CollectionUtils.isNotEmpty(page.getContent())) {
            BusinessLedger ledger = page.getContent().get(0);
            if (Objects.nonNull(ledger)) {
                List<BusinessLedgerTask> businessLedgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                if (CollectionUtils.isNotEmpty(businessLedgerTasks)) {
                    for (BusinessLedgerTask task : businessLedgerTasks) {
                        arrayList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                    }
                }
            }
        }

        List<LedgerJiaoYiDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerJiaoYiDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);


        /*//查询未完成的台账
        Map<String, Object> param = new HashMap<>();
        param.put("EQ_status", "0");
        List<String> typeList = Arrays.asList("dazong_jiaoyi", "guzhi_xingquan", "jijin_tougu");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (CollectionUtils.isNotEmpty(page.getContent())) {
//            LocalDateTime oneWeekAgo = LocalDateTime.now().minus(1, ChronoUnit.WEEKS);
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            for (BusinessLedger ledger : page.getContent()) {
                List<BusinessLedgerTask> taskList = ledgerService.listLedgerByLedgerId(ledger.getId());
                taskList = taskList.stream().filter(e -> ("Y".equals(e.getWorkValueRequire()) && "0".equals(e.getStatus()))).collect(Collectors.toList());
                taskList = taskList.stream().sorted(Comparator.comparing(BusinessLedgerTask::getTaskSort)).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(taskList)) {
                    continue;
                }
                BusinessLedgerTask task = taskList.get(0);
                if ("dazong_jiaoyi".equals(ledger.getToTaskType())) {
                    //大宗交易
                    daZongList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("guzhi_xingquan".equals(ledger.getToTaskType())) {
                    //自有股质/行权融资
                    ziYouGuZhiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("jijin_tougu".equals(ledger.getToTaskType())) {
                    //基金投顾
                    jiJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                }
            }
        }


        //查询当日完成的台账
        Map<String, Object> finishParam = new HashMap<>();
        finishParam.put("EQ_status", "1");
        finishParam.put("EQ_finishTime", date);
        finishParam.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> finishPage = ledgerService.findLedgerPage(1, 1000, finishParam);
        if (CollectionUtils.isNotEmpty(finishPage.getContent())) {
            Set<String> nameSet = perfMap.keySet();
            for (BusinessLedger ledger : finishPage.getContent()) {
                LedgerJiaoYiDtoItem perfDtoItem = perfMap.get(ledger.getFinishUserName());
                if (nameSet.contains(ledger.getFinishUserName())) {
                    perfDtoItem = perfMap.get(ledger.getFinishUserName());
                }
                if (Objects.isNull(perfDtoItem)) {
                    continue;
                }


                if ("dazong_jiaoyi".equals(ledger.getToTaskType())) {
                    //大宗交易
                    daZongList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    ledgerTasks = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerJiaoYiDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }

                        if (StringUtils.isNotBlank(task.getWorkValue())) {
                            try {
                                Integer count = Integer.parseInt(task.getWorkValue().trim());

                                if (Objects.nonNull(count) && count > 0) {
                                    if (task.getWorkType().contains("交易执行")) {
                                        taskLedgerPerfDtoItem.setDaZongHour(taskLedgerPerfDtoItem.getDaZongHour() + 20 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 20 * count);
                                    }
                                }
                            } catch (Exception e) {
                                log.error("今日桌面大宗交易计算异常{}", JSON.toJSONString(task));
                            }
                        }
                    }

                } else if ("guzhi_xingquan".equals(ledger.getToTaskType())) {
                    //自有股质/行权融资
                    ziYouGuZhiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    ledgerTasks = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerJiaoYiDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }

                        if (StringUtils.isNotBlank(task.getWorkValue())) {
                            try {
                                Integer count = Integer.parseInt(task.getWorkValue().trim());

                                if (Objects.nonNull(count) && count > 0) {
                                    if (task.getWorkItem().contains("开通客户权限")) {
                                        taskLedgerPerfDtoItem.setZiYouGuZhiHour(taskLedgerPerfDtoItem.getZiYouGuZhiHour() + 20 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 20 * count);
                                    } else if (task.getWorkItem().contains("授信设置")) {
                                        taskLedgerPerfDtoItem.setZiYouGuZhiHour(taskLedgerPerfDtoItem.getZiYouGuZhiHour() + 20 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 20 * count);
                                    } else if (task.getWorkItem().contains("标的券设置")) {
                                        taskLedgerPerfDtoItem.setZiYouGuZhiHour(taskLedgerPerfDtoItem.getZiYouGuZhiHour() + 20 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 20 * count);
                                    }
                                }
                            } catch (Exception e) {
                                log.error("今日桌面大宗交易计算异常{}", JSON.toJSONString(task));
                            }
                        }
                    }
                } else if ("jijin_tougu".equals(ledger.getToTaskType())) {
                    //基金投顾
                    jiJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setJiJinHour(perfDtoItem.getJiJinHour() + 300);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 300);

                }

            }
        }

        List<LedgerJiaoYiDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerJiaoYiDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);*/

        return PlatformResponse.successData(res);
    }


    /**
     * 今日桌面-固收运营岗
     *
     * @param request
     * @return
     */
    public PlatformResponse<LedgerGuShouDto> screenGuShou(String date, HttpServletRequest request) {
        LedgerGuShouDto res = new LedgerGuShouDto();
        //固收报表类gushou_yunying_bb
        List<LedgerDesktopDtoItem> baoBiaoList = Lists.newArrayList();
        //固收互换类gushou_yunying_hh
        List<LedgerDesktopDtoItem> huHuanList = Lists.newArrayList();
        //固收结算类gushou_yunying_js
        List<LedgerDesktopDtoItem> jieSuanList = Lists.newArrayList();
        //固收资金类gushou_yunying_zj
        List<LedgerDesktopDtoItem> ziJinList = Lists.newArrayList();


        res.setBaoBiaoList(baoBiaoList);
        res.setHuHuanList(huHuanList);
        res.setJieSuanList(jieSuanList);
        res.setZiJinList(ziJinList);


        Map<String, LedgerGuShouDtoItem> perfMap = new HashedMap();
        perfMap.put("安恬", LedgerGuShouDtoItem.builder().userName("安恬").userOaAccount("ant").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
        perfMap.put("范漪漪", LedgerGuShouDtoItem.builder().userName("范漪漪").userOaAccount("fanyy").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
        perfMap.put("何泉震", LedgerGuShouDtoItem.builder().userName("何泉震").userOaAccount("heqzh").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
        perfMap.put("姚金岐", LedgerGuShouDtoItem.builder().userName("姚金岐").userOaAccount("yaojq").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());


        Map<String, Object> param = new HashMap<>();
        List<String> typeList = Arrays.asList("jrsc_zhyygtz");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        param.put("GTE_createTime", DateUtil.getNowDateString());
        param.put("LTE_createTime", dateFormat.format(calendar.getTime()));

        ArrayList<LedgerDesktopDtoItem> arrayList = Lists.newArrayList();
        res.setTaskList(arrayList);

        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (Objects.nonNull(page) && CollectionUtils.isNotEmpty(page.getContent())) {
            BusinessLedger ledger = page.getContent().get(0);
            if (Objects.nonNull(ledger)) {
                List<BusinessLedgerTask> businessLedgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                if (CollectionUtils.isNotEmpty(businessLedgerTasks)) {
                    for (BusinessLedgerTask task : businessLedgerTasks) {
                        arrayList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                    }
                }
            }
        }

        List<LedgerGuShouDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerGuShouDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);

        /*//查询未完成的台账
        Map<String, Object> param = new HashMap<>();
        List<String> typeList = Arrays.asList("gushou_yunying_bb", "gushou_yunying_hh", "gushou_yunying_js", "gushou_yunying_zj");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        param.put("EQ_status", "0");
        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (CollectionUtils.isNotEmpty(page.getContent())) {
            for (BusinessLedger ledger : page.getContent()) {
                List<BusinessLedgerTask> taskList = ledgerService.listLedgerByLedgerId(ledger.getId());
                taskList = taskList.stream().filter(e -> ("Y".equals(e.getWorkValueRequire()) && "0".equals(e.getStatus()))).collect(Collectors.toList());
                taskList = taskList.stream().sorted(Comparator.comparing(BusinessLedgerTask::getTaskSort)).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(taskList)) {
                    continue;
                }
                BusinessLedgerTask task = taskList.get(0);
                if ("gushou_yunying_bb".equals(ledger.getToTaskType())) {
                    //固收报表类gushou_yunying_bb
                    baoBiaoList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("gushou_yunying_hh".equals(ledger.getToTaskType())) {
                    //固收互换类gushou_yunying_hh
                    huHuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("gushou_yunying_js".equals(ledger.getToTaskType())) {
                    //固收结算类gushou_yunying_js
                    jieSuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                } else if ("gushou_yunying_zj".equals(ledger.getToTaskType())) {
                    //固收资金类gushou_yunying_zj
                    ziJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkItem()).taskId(task.getId()).build());
                }
            }
        }


        //查询当日完成的台账
        Map<String, Object> finishParam = new HashMap<>();
        finishParam.put("EQ_status", "1");
        finishParam.put("EQ_finishTime", date);
        finishParam.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> finishPage = ledgerService.findLedgerPage(1, 1000, finishParam);
        if (CollectionUtils.isNotEmpty(finishPage.getContent())) {
            Set<String> nameSet = perfMap.keySet();
            for (BusinessLedger ledger : finishPage.getContent()) {
                LedgerGuShouDtoItem perfDtoItem = null;
                if (nameSet.contains(ledger.getFinishUserName())) {
                    perfDtoItem = perfMap.get(ledger.getFinishUserName());
                }


                if ("gushou_yunying_bb".equals(ledger.getToTaskType())) {
                    //固收报表类gushou_yunying_bb
                    baoBiaoList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setBaoBiaoHour(perfDtoItem.getBaoBiaoHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                } else if ("gushou_yunying_hh".equals(ledger.getToTaskType())) {
                    //固收互换类gushou_yunying_hh
                    huHuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());

                    List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                    ledgerTasks = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerGuShouDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }

                        if (StringUtils.isNotBlank(task.getWorkValue())) {
                            try {
                                Integer count = Integer.parseInt(task.getWorkValue().trim());

                                if (Objects.nonNull(count) && count > 0) {
                                    if (task.getWorkItem().contains("新增场外互换报送")) {
                                        taskLedgerPerfDtoItem.setHuHuanHour(taskLedgerPerfDtoItem.getHuHuanHour() + 25 * count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 25 * count);
                                    }
                                }
                            } catch (Exception e) {
                                log.error("今日桌面固收互换类计算异常{}", JSON.toJSONString(task));
                            }
                        }
                    }
                } else if ("gushou_yunying_js".equals(ledger.getToTaskType())) {
                    //固收结算类gushou_yunying_js
                    jieSuanList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setJieSuanHour(perfDtoItem.getJieSuanHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                } else if ("gushou_yunying_zj".equals(ledger.getToTaskType())) {
                    //固收资金类gushou_yunying_zj
                    ziJinList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    perfDtoItem.setZiJinHour(perfDtoItem.getZiJinHour() + 60);
                    perfDtoItem.setManHour(perfDtoItem.getManHour() + 60);
                }


            }
        }

        List<LedgerGuShouDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerGuShouDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);*/

        return PlatformResponse.successData(res);
    }


    /**
     * 今日桌面-清算岗
     *
     * @param request
     * @return
     */
    public PlatformResponse<LedgerQingSuanDto> screenQingSuan(String date, HttpServletRequest request) {
        LedgerQingSuanDto res = new LedgerQingSuanDto();

        LocalDateTime temp = LocalDate.parse(date).atStartOfDay();
        LocalDateTime localDateTime = temp.minusDays(1);
        //测试工作qs_xtce
        List<LedgerDesktopDtoItem> ceShiList = Lists.newArrayList();
        List<LedgerDesktopDtoItem> qiTaList = Lists.newArrayList();

        res.setCeShiList(ceShiList);
        res.setQiTaList(qiTaList);

        Map<String, LedgerQingSuanDtoItem> perfMap = new HashedMap();
        perfMap.put("杨珂", LedgerQingSuanDtoItem.builder().userName("杨珂").userOaAccount("yangke").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
        perfMap.put("徐苏", LedgerQingSuanDtoItem.builder().userName("徐苏").userOaAccount("xus").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
        perfMap.put("刘涵煜", LedgerQingSuanDtoItem.builder().userName("刘涵煜").userOaAccount("liuhy").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
        perfMap.put("许晟晖", LedgerQingSuanDtoItem.builder().userName("许晟晖").userOaAccount("xush").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
        perfMap.put("徐浩昕", LedgerQingSuanDtoItem.builder().userName("徐浩昕").userOaAccount("xhx").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());

        //查询未完成的台账
        Map<String, Object> param = new HashMap<>();
        param.put("EQ_status", "0");
        List<String> typeList = Arrays.asList("qs_xtce", "qs_qt");
        param.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> page = ledgerService.findLedgerPage(1, 1000, param);
        if (CollectionUtils.isNotEmpty(page.getContent())) {
            for (BusinessLedger ledger : page.getContent()) {
                List<BusinessLedgerTask> taskList = ledgerService.listLedgerByLedgerId(ledger.getId());

                List<BusinessLedgerTask> waitFinishList = Lists.newArrayList();
                waitFinishList = taskList.stream().filter(e -> ("0".equals(e.getStatus()))).collect(Collectors.toList());
                waitFinishList = taskList.stream().sorted(Comparator.comparing(BusinessLedgerTask::getTaskSort)).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(taskList)) {
                    continue;
                }

                BusinessLedgerTask task = waitFinishList.get(0);
                if ("qs_xtce".equals(ledger.getToTaskType())) {
                    //测试工作qs_xtce
                    ceShiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkType() + task.getWorkItem()).taskId(task.getId()).build());
                } else if ("qs_qt".equals(ledger.getToTaskType())) {
                    //测试工作qs_xtce
                    qiTaList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName(task.getWorkType() + task.getWorkItem()).taskId(task.getId()).build());
                }

                taskList = taskList.stream().filter(e -> ("1".equals(e.getStatus()))).collect(Collectors.toList());
                for (BusinessLedgerTask ledgerTask : taskList) {
                    LedgerQingSuanDtoItem taskLedgerPerfDtoItem = perfMap.get(ledgerTask.getFinishUserName());
                    if (Objects.isNull(taskLedgerPerfDtoItem)) {
                        continue;
                    }
                    if (StringUtils.isBlank(task.getFinishUserName())) {
                        continue;
                    }
                    if ("qs_xtce".equals(ledger.getToTaskType())) {
                        //测试工作qs_xtce
                        if (task.getWorkItem().contains("系统测试")) {
                            if (StringUtils.isNotBlank(task.getWorkValue())) {
                                try {
                                    Integer count = Integer.parseInt(task.getWorkValue().trim());
                                    if (Objects.nonNull(count) && count > 0) {
                                        if (task.getWorkType().contains("系统测试")) {
                                            taskLedgerPerfDtoItem.setZhuDongHour(taskLedgerPerfDtoItem.getZhuDongHour() + count);
                                            taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + count);
                                        }
                                    }
                                } catch (Exception e) {
                                    log.error("今日桌面系统测试计算-待完成异常{}", JSON.toJSONString(task));
                                }
                            }
                        }
                    }
                    if ("qs_qt".equals(ledger.getToTaskType())) {
                        if (task.getWorkItem().contains("营业部迁移沟通") || task.getWorkItem().contains("中登结算参与人信息修改")) {
                            taskLedgerPerfDtoItem.setZhuDongHour(taskLedgerPerfDtoItem.getZhuDongHour() + 30);
                            taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 30);
                        }
                    }

                }
            }
        }

        //查询当日完成的台账
        Map<String, Object> finishParam = new HashMap<>();
        finishParam.put("EQ_status", "1");
        finishParam.put("EQ_finishTime", date);
        finishParam.put("INSTR_toTaskType", String.join(",", typeList));
        Page<BusinessLedger> finishPage = ledgerService.findLedgerPage(1, 1000, finishParam);
        if (CollectionUtils.isNotEmpty(finishPage.getContent())) {
            Set<String> nameSet = perfMap.keySet();
            for (BusinessLedger ledger : finishPage.getContent()) {
                LedgerQingSuanDtoItem perfDtoItem = null;
                if (nameSet.contains(ledger.getFinishUserName())) {
                    perfDtoItem = perfMap.get(ledger.getFinishUserName());
                }

                List<BusinessLedgerTask> ledgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                ledgerTasks = ledgerTasks.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());

                if ("qs_xtce".equals(ledger.getToTaskType())) {
                    if (CollectionUtils.isEmpty(ledgerTasks)) {
                        continue;
                    }
                    //测试工作qs_xtce
                    ceShiList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerQingSuanDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }
                        if (StringUtils.isBlank(task.getFinishUserName())) {
                            continue;
                        }
//                        if (task.getWorkItem().contains("系统测试")) {
//                            taskLedgerPerfDtoItem.setZhuDongHour(taskLedgerPerfDtoItem.getZhuDongHour() + 30);
//                            taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 30);
//                        }

                        if (StringUtils.isNotBlank(task.getWorkValue())) {
                            try {
                                Integer count = Integer.parseInt(task.getWorkValue().trim());
                                if (Objects.nonNull(count) && count > 0) {
                                    if (task.getWorkType().contains("系统测试")) {
                                        taskLedgerPerfDtoItem.setZhuDongHour(taskLedgerPerfDtoItem.getZhuDongHour() + count);
                                        taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + count);
                                    }
                                }
                            } catch (Exception e) {
                                log.error("今日桌面系统测试计算异常{}", JSON.toJSONString(task));
                            }
                        }

                    }
                } else if ("qs_qt".equals(ledger.getToTaskType())) {
                    if (CollectionUtils.isEmpty(ledgerTasks)) {
                        continue;
                    }
                    //其他 qs_qt
                    qiTaList.add(LedgerDesktopDtoItem.builder().ledgerId(ledger.getId()).ledgerName(ledger.getName()).taskName("任务已完成").finishUserName(ledger.getFinishUserName()).finishId(ledger.getFinishId()).build());
                    for (BusinessLedgerTask task : ledgerTasks) {
                        LedgerQingSuanDtoItem taskLedgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                        if (Objects.isNull(taskLedgerPerfDtoItem)) {
                            continue;
                        }
                        if (StringUtils.isBlank(task.getFinishUserName())) {
                            continue;
                        }
                        if (task.getWorkItem().contains("营业部迁移沟通") || task.getWorkItem().contains("中登结算参与人信息修改")) {
                            taskLedgerPerfDtoItem.setZhuDongHour(taskLedgerPerfDtoItem.getZhuDongHour() + 30);
                            taskLedgerPerfDtoItem.setManHour(taskLedgerPerfDtoItem.getManHour() + 30);
                        }

                    }
                }


            }
        }

        //todo  处理今日台账
        Map<String, Object> todayParam = new HashMap<>();

        todayParam.put("GT_createTime", localDateTime);

        todayParam.put("LTE_createTime", LocalDateTime.now());
        todayParam.put("INSTR_toTaskType", String.join(",", Arrays.asList("qs_uf20_ls", "qs_uf20_jg", "qs_ncqsxt", "qs_sjqffzxt", "qs_jjtgxt", "qs_frxt", "qs_o32", "qs_pbxt", "qs_i2xt", "qs_llxt", "qs_htxt", "qs_uf20_qz")));
        Page<BusinessLedger> todayPage = ledgerService.findLedgerPage(1, 1000, todayParam);
        if (CollectionUtils.isNotEmpty(todayPage.getContent())) {

            for (BusinessLedger ledger : todayPage.getContent()) {
                List<BusinessLedgerTask> businessLedgerTasks = ledgerService.listLedgerByLedgerId(ledger.getId());
                ledger.setTaskList(businessLedgerTasks);
            }
            Map<String, BusinessLedger> todoTaskLedgerMap = todayPage.getContent().stream().collect(Collectors.toMap(BusinessLedger::getToTaskType, e -> e, (i, j) -> j));

            //零售柜台uf20
            BusinessLedger qsUf20Ls = todoTaskLedgerMap.get("qs_uf20_ls");
            res.setLingShouLedger(qsUf20Ls);
            if (Objects.nonNull(qsUf20Ls)) {
                List<BusinessLedgerTask> taskList = qsUf20Ls.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("红利税/三板/现金添利异常/ETF差额")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 40);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 40);
                            } else if (task.getWorkItem().contains("多金融日间")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 20);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 20);
                            } else if (task.getWorkItem().contains("多金融日间+新股弃购")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            } else if (task.getWorkItem().contains("股质/报价回购/三板")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 15);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 15);
                            } else if (task.getWorkItem().contains("合格投资者/期权/盯市")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 20);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 20);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 140);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 140);
                                //周一170
                                Calendar calendar = Calendar.getInstance();
                                if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
                                    ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 180);
                                    ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 180);
                                }
                            }
                        }
                    }
                }
            }

            //机构柜台uf20
            BusinessLedger qsUf20Jg = todoTaskLedgerMap.get("qs_uf20_jg");
            res.setJiGouLedger(qsUf20Jg);
            if (Objects.nonNull(qsUf20Jg)) {
                List<BusinessLedgerTask> taskList = qsUf20Jg.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("股息红利税转入")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 8);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 8);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            }
                        }
                    }
                }
            }

            //内存清算
            BusinessLedger qsNcqsxt = todoTaskLedgerMap.get("qs_ncqsxt");
            res.setNeiCunLedger(qsNcqsxt);
            if (Objects.nonNull(qsNcqsxt)) {
                List<BusinessLedgerTask> taskList = qsNcqsxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 50);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 50);
                            }
                        }
                    }
                }
            }

            //数据清分
            BusinessLedger qsSjqffzxt = todoTaskLedgerMap.get("qs_sjqffzxt");
            res.setShuJuLedger(qsSjqffzxt);
            if (Objects.nonNull(qsSjqffzxt)) {
                List<BusinessLedgerTask> taskList = qsSjqffzxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("两融对账单&交割单")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 10);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 10);
                            } else if (task.getWorkItem().contains("产品数据发送")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 15);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 15);
                            } else if (task.getWorkItem().contains("二次银行文件核对")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 10);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 10);
                            } else if (task.getWorkItem().contains("普通&期权对账单")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 15);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 15);
                            }
                        }
                    }
                }
            }

            //基金投顾
            BusinessLedger qsJjtgxt = todoTaskLedgerMap.get("qs_jjtgxt");
            res.setJiJinLedger(qsJjtgxt);
            if (Objects.nonNull(qsJjtgxt)) {
                List<BusinessLedgerTask> taskList = qsJjtgxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("自研")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 140);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 140);
                            } else if (task.getWorkItem().contains("国联")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 15);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 15);
                            } else if (task.getWorkItem().contains("国联&自研")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 140);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 140);
                            }
                        }
                    }
                }
            }

            //法人系统
            BusinessLedger qsFrxt = todoTaskLedgerMap.get("qs_frxt");
            res.setFaRenLedger(qsFrxt);
            if (Objects.nonNull(qsFrxt)) {
                List<BusinessLedgerTask> taskList = qsFrxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("经纪业务快报&财务报表&三板报送")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 15);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 15);
                            } else if (task.getWorkItem().contains("代销产品收款资金核对")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 40);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 40);
                            } else if (task.getWorkItem().contains("三板代办数据处理")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 10);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 10);
                            } else if (task.getWorkItem().contains("主办确权数据沟通")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 150);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 150);
                            }
                        }
                    }
                }
            }

            //O32
            BusinessLedger qsO32 = todoTaskLedgerMap.get("qs_o32");
            res.setO32Ledger(qsO32);
            if (Objects.nonNull(qsO32)) {
                List<BusinessLedgerTask> taskList = qsO32.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("日初资金调整")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 10);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 10);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 60);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 60);
                            }
                        }
                    }
                }
            }


            //PB系统
            BusinessLedger qsPbxt = todoTaskLedgerMap.get("qs_pbxt");
            res.setPbLedger(qsPbxt);
            if (Objects.nonNull(qsPbxt)) {
                List<BusinessLedgerTask> taskList = qsPbxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("分仓核对")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 5);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 5);
                            } else if (task.getWorkItem().contains("股息红利税")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 2);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 2);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 60);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 60);
                            }
                        }
                    }
                }
            }

            //i2
            BusinessLedger qsI2xt = todoTaskLedgerMap.get("qs_i2xt");
            res.setI2Ledger(qsI2xt);
            if (Objects.nonNull(qsI2xt)) {
                List<BusinessLedgerTask> taskList = qsI2xt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("脚本执行&O32余额核对")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 5);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 5);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 60);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 60);
                            }
                        }
                    }
                }
            }

            //凌瓴系统
            BusinessLedger qsLlxt = todoTaskLedgerMap.get("qs_llxt");
            res.setLingLingLedger(qsLlxt);
            if (Objects.nonNull(qsLlxt)) {
                List<BusinessLedgerTask> taskList = qsLlxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("系统测试")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            } else if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 20);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 20);
                            }
                        }
                    }
                }
            }

            //衡泰系统
            BusinessLedger qsHtxt = todoTaskLedgerMap.get("qs_htxt");
            res.setHengTaiLedger(qsHtxt);
            if (Objects.nonNull(qsHtxt)) {
                List<BusinessLedgerTask> taskList = qsHtxt.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("T-1日终清算（香港子）")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 10);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 10);
                            } else if (task.getWorkItem().contains("T日日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            }
                        }
                    }
                }
            }

            //期权全真环境
            BusinessLedger qsUf20Qz = todoTaskLedgerMap.get("qs_uf20_qz");
            res.setQiQuanLedger(qsUf20Qz);
            if (Objects.nonNull(qsUf20Qz)) {
                List<BusinessLedgerTask> taskList = qsUf20Qz.getTaskList();
                if (CollectionUtils.isNotEmpty(taskList)) {
                    List<BusinessLedgerTask> tasks = taskList.stream().filter(e -> StringUtils.isNotBlank(e.getFinishUserName())).collect(Collectors.toList());
                    if (CollectionUtils.isNotEmpty(tasks)) {
                        for (BusinessLedgerTask task : tasks) {
                            LedgerQingSuanDtoItem ledgerPerfDtoItem = perfMap.get(task.getFinishUserName());
                            if (Objects.isNull(ledgerPerfDtoItem)) {
                                continue;
                            }
                            if (task.getWorkItem().contains("日终清算")) {
                                ledgerPerfDtoItem.setZhuDongHour(ledgerPerfDtoItem.getZhuDongHour() + 30);
                                ledgerPerfDtoItem.setManHour(ledgerPerfDtoItem.getManHour() + 30);
                            }
                        }
                    }
                }
            }
        }


        List<LedgerQingSuanDtoItem> perfList = Lists.newArrayList();
        for (String key : perfMap.keySet()) {
            perfList.add(perfMap.get(key));
        }

        perfList = perfList.stream().sorted(Comparator.comparing(LedgerQingSuanDtoItem::getManHour).reversed()).collect(Collectors.toList());
        res.setPerfList(perfList);

        return PlatformResponse.successData(res);
    }


}